package emil.poker.util;

import java.util.HashMap;

import emil.poker.Decision;

public class PokerUtils {
	public static boolean isLegal( Decision decision, Decision[] legal ) {
		if ( legal != null ) {
			for (Decision decision2 : legal) {
				if ( decision2.equals( decision ) ) {
					return true;
				}
			}
		}
		return false;
	}
	
	public static synchronized HashMap<Integer, Integer> getLegalNumbers()
	{
		if (legalNumbers == null){
			// it's ok, we can call this constructor
			legalNumbers = new HashMap<Integer, Integer> ();
			legalNumbers.put( 0, 0);
			legalNumbers.put( 1, 1);
			legalNumbers.put( 2, 2);
			legalNumbers.put( 3,4);
			legalNumbers.put( 4,4);
			legalNumbers.put( 5,4);
			legalNumbers.put( 6,8);
			legalNumbers.put( 7,8);
			legalNumbers.put( 8,8);
			legalNumbers.put( 9,8);
			legalNumbers.put( 10,8);
		}
		return legalNumbers;
	}
	
	private static HashMap<Integer, Integer> legalNumbers;
	
	public static int getLegalNumber( int i){
		return getLegalNumbers().get( i );
	}
}
